﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Sayeet
{
    public partial class ChatPane : UserControl
    {
        public string FromAddress;
        public string ToAddress;
        public Chat chat;

        public enum MessageType
        {
            incoming,
            outcoming
        }

        public ChatPane()
        {
            InitializeComponent();
            //appData = ad;
        }

        public void addMessage(string text, MessageType type)
        {
            if(type == MessageType.incoming)
                chatText.Text += ToAddress;
            if (type == MessageType.outcoming)
                chatText.Text += FromAddress;

            chatText.Text +=(": " + text + "\n");
        }

        private void sendButton_Click(object sender, EventArgs e)
        {
            if (inputText.Text != "")
            {
                addMessage(inputText.Text, MessageType.outcoming);
                chat.contact.sendMessage(inputText.Text);
                inputText.Clear();
                
            }
        }

        private void inputText_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if(!inputText.Text.StartsWith("\n"))
                    sendButton_Click(sender, e);
            }
        }

        private void inputText_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                inputText.Clear();
            }
        }
    }
}
